package com.cn.aam.checaiduo.ui.me.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cn.aam.checaiduo.R;
import com.cn.aam.checaiduo.base.adapter.BaseRecycerAdapter;
import com.cn.aam.checaiduo.base.adapter.holder.BaseRecyclerViewHolder;
import com.cn.aam.checaiduo.utils.WindowsUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * monker on 2017/5/25.
 * 签到界面日历adapter
 */

public class CalenderAdapter extends BaseRecycerAdapter<CalenderAdapter.DateItemB> {

    public CalenderAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    protected BaseRecyclerViewHolder getViewHolder(View picNewsView) {
        return new DateHolder(picNewsView);
    }

    @Override
    protected int getItemLayoutRes() {
        return R.layout.list_item_calender;
    }

    @Override
    protected void ItemVIewChange(BaseRecyclerViewHolder recyclerholder, final int position) {
        final DateHolder holder = (DateHolder) recyclerholder;
        holder.signDay.setText(getItem(position).getDay());
        holder.signWeek.setText(getItem(position).getWeek());
        int sigleItemWith = WindowsUtils.getScreenWidth(mContext) / 7;
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(sigleItemWith, WindowsUtils.dip2px(50));
        holder.ll.setLayoutParams(lp);


        if (getItem(position).isToday()) {
            holder.signDay.setBackground(ContextCompat.getDrawable(mContext, R.drawable.bg_signin_circle_filter));
            holder.signDay.setTextColor(ContextCompat.getColor(mContext, R.color.white));
        } else if (getItem(position).isSign()) {
            holder.signDay.setBackground(ContextCompat.getDrawable(mContext, R.drawable.bg_circle_gray));
            holder.signDay.setTextColor(ContextCompat.getColor(mContext, R.color.textColor));
        } else if (getItem(position).isClick()) {
            holder.signDay.setBackground(ContextCompat.getDrawable(mContext, R.drawable.btn_yellow_shape));
            holder.signDay.setTextColor(ContextCompat.getColor(mContext, R.color.white));
        } else {
            holder.signDay.setBackground(null);
            holder.signDay.setTextColor(ContextCompat.getColor(mContext, R.color.textColor));
        }


//        holder.ll.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                setDefaultClick();
//                getItem(position).setClick(true);
//                notifyDataSetChanged();
//            }
//        });
    }

    private void setDefaultClick() {
        for (DateItemB d : getDataList()) {
            d.setClick(false);
        }
    }

    class DateHolder extends BaseRecyclerViewHolder {
        @BindView(R.id.sign_tv_week)
        TextView signWeek;
        @BindView(R.id.sign_tv_day)
        TextView signDay;

        @BindView(R.id.sign_ll)
        LinearLayout ll;

        public DateHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    public static class DateItemB {

        private String week;//周几
        private String day;//几号
        private boolean isToday;//是否今天
        private boolean isSign;//是否签到
        private boolean isClick;//是否点击

        private String detailDate;

        public String getWeek() {
            return week;
        }

        public void setWeek(String week) {
            this.week = week;
        }

        public String getDay() {
            return day;
        }

        public void setDay(String day) {
            this.day = day;
        }

        public boolean isToday() {
            return isToday;
        }

        public void setToday(boolean today) {
            isToday = today;
        }

        public boolean isSign() {
            return isSign;
        }

        public void setSign(boolean sign) {
            isSign = sign;
        }

        public boolean isClick() {
            return isClick;
        }

        public void setClick(boolean click) {
            isClick = click;
        }

        public String getDetailDate() {
            return detailDate;
        }

        public void setDetailDate(String detailDate) {
            this.detailDate = detailDate;
        }
    }
}
